package com.easychat.utils;

import cn.hutool.core.bean.BeanUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @author kyle.li
 * @version 1.0
 * @description: TODO
 * @date 2024/7/4 21:38
 */
public class CopyTools {
    public static <T, S> List<T> copyList(List<S> sList, Class<T> classz){
        ArrayList<T> list = new ArrayList<T>();
        for (S s : sList) {
            T t = null;
            try {
                t = classz.newInstance();
            }catch (Exception e){
                e.printStackTrace();
            }
            BeanUtil.copyProperties(s, t);
            list.add(t);
        }
        return list;
    }

    public static <T, S> T copyEntity(S s, Class<T> classz){
        T t = null;
        try{
            t = classz.newInstance();
        }catch (Exception e){
            e.printStackTrace();
        }
        BeanUtil.copyProperties(s, t);
        return t;
    }

}
